package nowcoder;

import java.io.*;
import java.util.*;

public class A_68 {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
    static int n, m;
    static int T;

    static int cin() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static void main(String[] args) throws IOException {
        T = cin();
        while (T -- > 0) {
            n = cin(); m = cin();
//        StringBuilder a = new StringBuilder(n + "");
//        StringBuilder b = new StringBuilder(m + "");
            StringBuilder res = new StringBuilder();
            char[] a = (n + "").toCharArray();
            char[] b = (m + "").toCharArray();
            if (a.length != b.length) {
                out.println(-1);
            } else {
                for (int i = 0; i < a.length; i ++ ) {
                    int x = a[i] - '0';
                    int y = b[i] - '0';
                    int multi = x * y;
                    res.append(multi);
                }
                out.println(res);
            }

        }
        out.flush();
    }
}
